package com.example.agriapp.view.fragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.agriapp.R;
import com.example.agriapp.data.AgriDatabaseHelper;
import com.example.agriapp.model.bean.User;
import com.example.agriapp.view.activity.CaiGouActivity;
import com.example.agriapp.view.activity.DianPuActivity;
import com.example.agriapp.view.activity.MyDingDanPinActivity;
import com.example.agriapp.view.activity.MyHuoPinActivity;

import java.io.Serializable;

public class SellerHomeFragment extends Fragment {


    private AgriDatabaseHelper agriDatabaseHelper;

    public static Fragment newInstance() {
        return new SellerHomeFragment();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        agriDatabaseHelper = new AgriDatabaseHelper(getContext());
        User user = (User) getActivity().getIntent().getSerializableExtra("USER");
        View inflate = inflater.inflate(R.layout.fragment_seller_home, container, false);
        TextView tvTodayYuan = inflate.findViewById(R.id.tvTodayYuan);
        TextView tvMonthYuan = inflate.findViewById(R.id.tvMonthYuan);
        TextView tvTotalYuan = inflate.findViewById(R.id.tvTotalYuan);
        tvTodayYuan.setText(String.valueOf(agriDatabaseHelper.getTodaySales()));
        tvMonthYuan.setText(String.valueOf(agriDatabaseHelper.getMonthSales()));
        tvTotalYuan.setText(String.valueOf(agriDatabaseHelper.getTodaySales()));
        inflate.findViewById(R.id.linmy).setOnClickListener( v -> startActivity(new Intent(getContext(), MyHuoPinActivity.class)));
        inflate.findViewById(R.id.lincaigou).setOnClickListener( v -> startActivity(new Intent(getContext(), CaiGouActivity.class)));
        inflate.findViewById(R.id.lindingdan).setOnClickListener( v -> startActivity(new Intent(getContext(), MyDingDanPinActivity.class)));
        inflate.findViewById(R.id.linjianjie).setOnClickListener( v ->{
                    Intent intent = new Intent(getContext(), DianPuActivity.class);
                    intent.putExtra("USER",user);
                    startActivity(intent);
                });
        return inflate;

    }
}